import React, { PureComponent } from 'react';
import { Form, Icon, Input, Button, Checkbox } from 'antd';
// import logoPic from '../../../../static/images/logo.png'
// import logoFoF from '../../../../static/images/logo-fof.png'

import img from '../../../../static/images/pic.png'
import Loading from '../../../components/common/Loading'

import constants from '../../../config/constants'

const FormItem = Form.Item;

@Form.create()
export default class LoginForm extends PureComponent {
	constructor(props) {
		super(props);
		this.state={
		}
	}

	handleSubmit = (e) => {
		e.preventDefault();
		const { form, login,loading } = this.props;
		form.validateFields((error, values) => {
			if (!error) {
				login(values);
			}
		});
		if(loading == false){
			this.props.form.setFieldsValue({
				password:''
			})
		}
	}


	render() {
		const { getFieldDecorator,setFieldsValue} = this.props.form;
		return (
			<div className="login-wrapper">
				<header><img src={constants.logoSrc} alt=""/><span>{constants.loginText}</span></header>
				<div className="content">
					<img src={img} />
					<Form onSubmit={this.handleSubmit} className="login-form">
						<FormItem label="用户名">
							{getFieldDecorator('userName', {
								rules: [{ required: true, message: '请输入用户名!' }],
							})(
								<Input  />,
							)}
						</FormItem>
						<FormItem label="密码"
						>
							{getFieldDecorator('password',{
	              initialValue: '',
	              rules: [
										{ required: true, message: '请输入密码' },
									],
	            })(
								<Input  type="password" />,
							)}
						</FormItem>
						<FormItem>
							<Button type="primary" htmlType="submit" className="login-form-button">
								登 录
							</Button>
						</FormItem>
					</Form>
			</div>
			</div>

		);
	}
}


// import React, {Component,PropTypes} from 'react';
// import {connect} from 'dva';
// import {routerRedux,withRouter } from 'dva/router';
// import { Form, Icon, Input, Button } from 'antd';

// import img from '../../../../static/images/pic.png';

// const FormItem = Form.Item;
// const LoginForm = ({
// 		dispatch,
// 		login,
// 		form: {
// 			getFieldDecorator,
// 			validateFields,
// 			getFieldsValue,
// 			setFieldsValue,
// 			getFieldsError,
// 			getFieldError,
// 			isFieldTouched },
// 	})=>{
// 	const userNameError = isFieldTouched('userName') && getFieldError('userName');
//  const passwordError = isFieldTouched('password') && getFieldError('password');
// 	function	handleSubmit(e){
// 		e.preventDefault();
// 		validateFields((error, fieldsValue) => {
// 			console.log('fieldsValue>>>>>>',fieldsValue)
// 			if (!error) {
// 				dispatch({
// 					type: 'login/login',
// 					payload: {
// 						...fieldsValue,
// 					}
// 				})
// 			}
// 		});
// 		setTimeout(function(){
// 　　setFieldsValue({
// 	   password: '',
// 	  });
// 　　},2000);
// 	}


// 		return (
// 			<div className="login-wrapper">
// 				<header><span>投后分析</span></header>
// 				<div className="content">
// 					<img src={img} />
// 					<Form onSubmit={handleSubmit} className="login-form">
// 						<FormItem
// 							label="用户名"
// 							validateStatus={userNameError ? 'error' : ''}
//      		help={userNameError || ''}
//      	>
// 							{getFieldDecorator('userName', {
// 								rules: [{ required: true, message: '请输入用户名!' }],
// 							})(
// 								<Input />,
// 							)}
// 						</FormItem>
// 						<FormItem
// 							label="密码"
// 							validateStatus={passwordError ? 'error' : ''}
//        help={passwordError || ''}
// 						>
// 							{getFieldDecorator('password', {
// 								rules: [{ required: true, message: '请输入密码' }],
// 							})(
// 								<Input type="password"/>,
// 							)}
// 						</FormItem>
// 						<FormItem>
// 							<Button type="primary" htmlType="submit" className="login-form-button">
// 								登 录
// 							</Button>
// 						</FormItem>
// 					</Form>
// 			</div>
// 			</div>

// 		);
// }

// LoginForm.propTypes = {
// 	form: PropTypes.object.isRequired,
// }

// export default connect(({login})=>({login}))(Form.create()(LoginForm))
